package cn.wjdiankong.levideo.dialog;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import cn.wjdiankong.levideo.R;
import cn.wjdiankong.levideo.utils.UIUtil;
import cn.wjdiankong.levideo.view.LevideoDialog;

public class ConfirmDialog {
	
	private LevideoDialog dialog;
	private View parentView;
	
	private TextView contentTxt;
	private TextView sureTxt, cancelTxt;
	private View sureView, cancelView;
	
	@SuppressLint("InflateParams")
	public ConfirmDialog(Activity act){
		if(parentView == null){
			parentView = LayoutInflater.from(act).inflate(R.layout.dialog_confirm, null);
		}
		if(dialog == null){
			dialog = new LevideoDialog(act, parentView, UIUtil.dip2px(act, 300), UIUtil.dip2px(act, 120));
		}
		contentTxt = (TextView) parentView.findViewById(R.id.content_txt);
		sureTxt = (TextView) parentView.findViewById(R.id.sure_txt);
		cancelTxt = (TextView) parentView.findViewById(R.id.cancel_txt);
		sureView = parentView.findViewById(R.id.sure_layout);
		cancelView = parentView.findViewById(R.id.cancel_layout);
		sureView.setVisibility(View.GONE);
		cancelView.setVisibility(View.GONE);
		dialog.setCanceledOnTouchOutside(false);
		dialog.setCancelable(false);
	}
	
	public ConfirmDialog setContentTxt(String str){
		if(contentTxt != null){
			contentTxt.setText(str);
		}
		return this;
	}
	
	public ConfirmDialog setLeftTxt(String str, OnClickListener listener){
		if(sureTxt != null && sureView != null){
			sureTxt.setText(str);
			sureView.setOnClickListener(listener);
			sureView.setVisibility(View.VISIBLE);
		}
		return this;
	}
	
	public ConfirmDialog setRightTxt(String str, OnClickListener listener){
		if(cancelTxt != null && cancelView != null){
			cancelTxt.setText(str);
			cancelView.setOnClickListener(listener);
			cancelView.setVisibility(View.VISIBLE);
		}
		return this;
	}
	
	public void show(){
		if(dialog != null){
			dialog.show();
		}
	}
	
	public void dimiss(){
		if(dialog != null){
			dialog.dismiss();
		}
	}

}
